﻿using System.IO;
using System.Text;
using Best.SmartCms.CodeGeneration.Model;
using Best.SmartCms.CodeGeneration.Template;

namespace Best.SmartCms.CodeGeneration.BuiderFactory
{
    public class DtoBuilder : CodeGenerationFactory
    {
        public override void BuilderTemplate(CodeGenerationDto dto)
        {
            if (!dto.IsBulderDto)
            {
                return;
            }

            OutPutPath = Path.Combine(BasePath, "Best.SmartCms.Dto");
            if (!Directory.Exists(OutPutPath))
            {
                Directory.CreateDirectory(OutPutPath);
            }

            var fileName= Path.Combine(OutPutPath, $"{dto.DomainName}Dto.cs");

            var temp = new DtoTempate(dto);
            var content = temp.TransformText();
            File.WriteAllText(fileName, content, Encoding.UTF8);
        }
    }
}
